﻿using Absky.Cache.Interface;
using Absky.MemoryCache;
using Absky.RedisCache;
using Absky.Util;

namespace Absky.Cache.Factory
{
    /// <summary>
    /// 缓存工厂
    /// </summary>
    public class CacheFactory
    {
        private static ICache cache = null;
        private static readonly object iockHelper = new object();

        public static ICache Cache
        {
            get
            {
                if (cache == null)
                {
                    lock (iockHelper)
                    {
                        if (cache == null)
                        {
                            cache = GlobalContext.SystemConfig.CacheProvider switch
                            {
                                "Redis" => new RedisCacheImp(),
                                _ => new MemoryCacheImp(),
                            };
                        }
                    }
                }
                return cache;
            }
        }
    }
}
